//
//  PMTabBarController.m
//
//  Created by Evan on 05/12/2016.
//  Copyright © 2016 Evan. All rights reserved.
//

#import "PMTabBarController.h"
#import "PMNavigationController.h"
#import "MeViewController.h"
#import "HomeViewController.h"
#import "CommonData.h"
#import "MallViewController.h"
#import "MeViewController.h"
#import "NoteViewController.h"

@interface PMTabBarController ()<UITabBarControllerDelegate>

@end
@implementation PMTabBarController


- (void)viewDidLoad {
    [super viewDidLoad];
    self.delegate = self;
    
    [self.tabBar setTintColor:[UIColor grayColor]];
    
    //动态设置tabbar的高度
    self.tabBar.frame = CGRectMake(self.tabBar.frame.origin.x, self.tabBar.frame.origin.y, self.tabBar.frame.size.width, KSHeight_TabBar);
    
    //设置tab的背景色
    UIView *viewBtab = [[UIView alloc]init];
    viewBtab.backgroundColor = [UIColor whiteColor];
    viewBtab.frame = self.tabBar.bounds;
    [self.tabBar insertSubview:viewBtab atIndex:0];
    
    HomeViewController* c1 = [[HomeViewController alloc]init];
    c1.tabBarItem.title=@"首页";
    c1.tabBarItem.image=[[UIImage imageNamed:@"tab1n"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    c1.tabBarItem.selectedImage = [[UIImage imageNamed:@"tab1"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    [c1.tabBarItem setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:COLOR_tabBarRed,NSForegroundColorAttributeName, nil] forState:UIControlStateSelected];
    PMNavigationController* navi1 = [[PMNavigationController alloc] initWithRootViewController:c1];
    
    MallViewController *c2=[[MallViewController alloc]init];
    c2.tabBarItem.title=@"交易中心";
    c2.tabBarItem.image=[[UIImage imageNamed:@"tab2n"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    c2.tabBarItem.selectedImage = [[UIImage imageNamed:@"tab2"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    [c2.tabBarItem setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:COLOR_tabBarRed,NSForegroundColorAttributeName, nil] forState:UIControlStateSelected];
    PMNavigationController* navi2 = [[PMNavigationController alloc] initWithRootViewController:c2];
    
    NoteViewController* c3 = [[NoteViewController alloc]init];
    c3.tabBarItem.title=@"账户";
    c3.tabBarItem.image=[[UIImage imageNamed:@"tab3n"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    c3.tabBarItem.selectedImage = [[UIImage imageNamed:@"tab3"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    [c3.tabBarItem setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:COLOR_tabBarRed,NSForegroundColorAttributeName, nil] forState:UIControlStateSelected];
    PMNavigationController* navi3 = [[PMNavigationController alloc] initWithRootViewController:c3];
    
    MeViewController *c4=[[MeViewController alloc]init];
    c4.tabBarItem.title=@"我的";
    c4.tabBarItem.image=[[UIImage imageNamed:@"tab4n"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    c4.tabBarItem.selectedImage = [[UIImage imageNamed:@"tab4"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    [c4.tabBarItem setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:COLOR_tabBarRed,NSForegroundColorAttributeName, nil] forState:UIControlStateSelected];
    PMNavigationController* navi4 = [[PMNavigationController alloc] initWithRootViewController:c4];
    
    self.viewControllers=@[navi1,navi2,navi3,navi4];
}

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
}


- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController{
    ///返回到rootview
//    if ([viewController isKindOfClass:[PMNavigationController class]]) {
//        [(PMNavigationController *)viewController popToRootViewControllerAnimated:YES];
//    }
}

@end
